package com.sheng.sign.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SessionFactory;

import com.sheng.sign.entity.Sign;

public class SignDaoImpl implements SignDao {
	
	 private SessionFactory sessionFactory;
	 
	 
		public SessionFactory getSessionFactory() {
			return sessionFactory;
		}
		public void setSessionFactory(SessionFactory sessionFactory) {
			this.sessionFactory = sessionFactory;
		}

	@Override
	public boolean add(Sign sign) {
		try {
			sessionFactory.getCurrentSession().save(sign);
			System.out.println("==来到了DaoImpl=="+sign);
			return true;
		} catch (HibernateException e) {
			return false;
		}
	}

	@Override
	public List<Sign> findAllList() {
		String hql = "from Sign where 1=1 ";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);  
        List list = query.list();  
        return list;
	}

	@Override
	public Sign findById(Sign sign) {
		Query query = sessionFactory.getCurrentSession().createQuery("from Student where id='"+sign.getId()+"'");  
		List list = query.list();  
		if (null != list && 0 < list.size()) {
			sign = (Sign) list.get(0);
		}
		return sign;
	}

}
